<!doctype html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta content="always" name="referrer">
    <#include "../common/header.html">

</head>
<body>
<!--最外面的灰底框,用于与ifram区别开-->
<div class="col-xs-12 lightgray_div">
    <!--白底框-->
    <div class="col-xs-12 white_div">
        <!--返回按钮-->
        <h4 class="back_div"><a href="javascript:history.back()" style="font-size: 16px; color: black; ">< 返回</a></h4>
        <div class="row all_input_div" style="margin-top: 8px">
            <div class="col-xs-6">
                <form class="form-horizontal" role="form" id="form1">
                    <input type="hidden" name="id" id="id" value="${id!?html}"/>

                    <div class="form-group">
                        <label class="col-xs-2 control-label"><em class="text-red">*</em>姓名</label>
                        <div class="col-xs-10">
                            <input type="text" class="form-control input_50b" id="name" name="name"
                                   placeholder="姓名">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-2 control-label"><em class="text-red">*</em>账号</label>
                        <div class="col-xs-10">
                            <input type="text" class="form-control input_50b" id="account" name="account"
                                   placeholder="账号">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-2 control-label"><em class="text-red">*</em>密码</label>
                        <div class="col-xs-10">
                            <input type="hidden" name="is_update_password" id="is_update_password" value="0" >
                            <input type="hidden" name="password" id="password" >
                            <input type="text" class="form-control input_50b"  id="show_password"
                                   placeholder="请输入密码">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-2 control-label">手机号</label>
                        <div class="col-xs-10">
                            <input type="text" class="form-control input_50b" name="phone" id="phone"
                                   placeholder="请输入手机号">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-2 control-label">邮箱</label>
                        <div class="col-xs-10">
                            <input type="text" class="form-control input_50b" name="email" id="email"
                                   placeholder="请输入邮箱">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-2 control-label">所属角色</label>
                        <div class="col-xs-10">
                            <select class="form-control input_50b"  name ="role_ids" id="role_ids" multiple="multiple" autofocus  >
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-2 control-label">备注</label>
                        <div class="col-xs-10">
                            <textarea type="text" class="form-control input_50b" style="height:120px;resize:none;"
                                      id="remark" name="remark"></textarea>
                        </div>
                    </div>

                </form>
                <div class="form-group ">
                    <label class="col-xs-2 control-label"></label>
                    <a class="gbn gbn-m" href="javascript:" id="btn_save" onclick="E.save();">保存</a>
                    <a class="gbn gbn-m gbn-red" href="javascript:" onclick="history.back();">返回</a>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<#include "../common/layui_init.html">
<script type="text/javascript">

    var E = {
        save: function () {
            var show_password=$("#show_password").val()
            if(!tool.isEmpty(show_password)){
                $("#is_update_password").val("1")
                $("#password").val($.md5(show_password));
            }
            $.post("${request.contextPath}/user/add_or_edit", $("#form1").serialize(), function (o) {
                if (o.code == 0) {
                    layer.msg(o.message);
                    location.href = document.referrer;
                } else {
                    layui_layer.error_alert(o.message);
                }
            })
        },
        load: function () {
            $.getJSON("${request.contextPath}/user/getById", {id: $("#id").val()}, function (o) {
                if (o.code == 0) {
                    $("#form1").setFormValues(o.data);
                    $("#show_password").attr("placeholder",o.data.password)

                }
            });
        }
    }
    $(function () {
        //回车点击事件 保存
        enter_event.event_save_click();
        $.ajaxSettings.async=false;
        select2_utils.load_select2("role_ids","请选择所属角色","${request.contextPath}/role/getAll",{})
        var id = $("#id").val()
        if (id != null && id != "") {
            E.load();
        }
    });
</script>
<#include "../common/footer-inner.html">
</html>
